/*
 * p4474.cpp
 *
 *  Created on: 2013-10-24
 *      Author: zy
 */
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;
bool vis[10001], disable[10];
int cnt;
char num[11];
int m, n, l, r, cas;
bool ok;
struct State
{
	char dig;
	int mod;
	int pre;
} q[10001];
void print(State now)
{
	char ans[10001];
	int cnt = 0;
	for (; now.pre != 0; now = q[now.pre])
	{
		cnt++;
		ans[cnt] = now.dig;
	}
	for (int i = cnt; i >= 1; i--)
		printf("%c", ans[i]);
	printf("\n");
}
void bfs()
{
	if (cnt == 0 || num[1] == '0' && cnt == 1)
		return;
	memset(vis, 0, sizeof(vis));
	State st, now, next;
	l = 0;
	r = 1;
	st.dig = '0';
	st.pre = 0;
	st.mod = (st.dig - '0') % n;
	q[1] = st;
	while (l < r)
	{
		l++;
		now = q[l];
		if (now.mod == 0 && l != 1)
		{
			ok = true;
			print(now);
			return;
		}
		for (int i = 1; i <= cnt; i++)
		{
			if (l == 1 && num[i] == '0')
				continue;
			next.dig = num[i];
			next.pre = l;
			next.mod = (now.mod * 10 + (num[i] - '0')) % n;
			if (!vis[next.mod])
			{
				vis[next.mod] = true;
				r++;
				q[r] = next;
			}
		}
	}

}
int main()
{
	cas = 0;
	while (scanf("%d%d", &n, &m) != EOF)
	{
		printf("Case %d: ", ++cas);
		memset(disable, 0, sizeof(disable));
		for (int i = 1; i <= m; i++)
		{
			int x;
			scanf("%d", &x);
			disable[x] = 1;
		}
		cnt = 0;
		for (int i = 0; i <= 9; i++)
			if (!disable[i])
			{
				cnt++;
				num[cnt] = i + '0';
			}
		ok = false;
		bfs();
		if (!ok)
			puts("-1");
	}
	return 0;
}
